/*
	Copyright (c) 2012 by karmaleaving@qq.com. All rights RESERVED.
*/
#ifndef __STD_MAP_H_VERSION_KL__
#define __STD_MAP_H_VERSION_KL__

#include "xtree.h"

KL_BEGIN
// CLASS map, multimap {
template<typename Key, typename Type, typename KeyLess = KL::less<Key>, 
typename Allocate = KL::allocator<Type>>
class map 
{
public:
	typedef KL::xtree<Key, Type, KeyLess, Allocate, false> _base;
	_base __base;
public:
	map()
	{
	}
	map(map const & o)
		: _base(o)
	{
	}
	map & operator = (map const &o)
	{
		__base = o.__base;
		return *this;
	}
	Type & operator[](Key const & key)
	{
		auto res = __base.insert(key);
		return res.first->second;
		
	}
};
template<typename Key, typename Type, typename KeyLess = KL::less<Key>, 
typename Allocate = KL::allocator<Type>>
class multimap : public KL::xtree<Key, Type, KeyLess, Allocate, true>
{
public:
	typedef KL::xtree<Key, Type, KeyLess, Allocate, true> _base;
public:
	multimap()
	{
	}
	multimap(multimap const & o)
		: _base(o)
	{
	}
	multimap & operator = (multimap const &o)
	{
		if(&o == this) return *this;
		*(_base*)this = (_base)o;
		return *this;
	}
};
// CLASS map, multimap }
// FUNCTION swap (for map) {
template<typename Type, typename Less, typename Allocate>
inline void swap(map<Type, Less, Allocate> &left, map<Type, Less, Allocate> &right)
{
	left.swap(right);
}
template<typename Type, typename Less, typename Allocate>
inline void swap(multimap<Type, Less, Allocate> &left, multimap<Type, Less, Allocate> &right)
{
	left.swap(right);
}
// FUNCTION swap (for map) }
KL_END
#endif // __STD_MAP_H_VERSION_KL__
